package com.cn.book.socketdemo8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(10086);

        Socket socket = server.accept();
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\myProjects\\java-architect\\java-architect\\TCP-demo\\src\\com\\cn\\book\\socketdemo8\\b.png"));
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("上传成功!");
        bw.newLine();
        bw.flush();

        bis.close();
        socket.close();
        server.close();
    }
}
